<template>
    <el-dialog width="500px" title="修改套餐" :visible.sync="dialogVisible" :close-on-click-modal="false">
      <el-form ref="ruleForm" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="原商品">
          <el-input v-model="goodsId" :disabled=true style="width: 200px;"/>
        </el-form-item>
        <el-form-item label="商品Id">
          <el-input v-model="form.goods_id" style="width: 200px;"/>
          <el-button style="margin-left: 20px;" @click="handleClick">搜索</el-button>
        </el-form-item>
        <el-form-item label="颜色">
            <el-radio-group v-model="form.color">
                <template v-for="item in colorList">
                    <el-radio-button :label="item.value" @click.native="color(item.id)"></el-radio-button>
                </template>

            </el-radio-group>
        </el-form-item>
        <el-form-item label="规格">
            <el-radio-group v-model="form.spec">
                <template v-for="item in specList">
                    <el-radio-button :label="item.value" @click.native="spec(item.id)"></el-radio-button>
                </template>
            </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="cancle">取 消</el-button>
        <el-button size="small" type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { setOrderRemark,getGoodsAttr,setGoodsAttr } from '@/api/order'
  export default {
    // props: ['orderId'],
    props: {
      orderId: {
        type: String,
        default: ''
      },
      goodsId: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        form: {
            orderId:'',
            color:'',
            spec:'',
            orderId:'',
            goods_id:'',
            // goodsId:''
        },
        colorList:[],
        specList:[],
        rules: {
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        },
        dialogVisible: false
      }
    },
    watch: {
      dialogVisible(val) {
        if (val) {
            this.form.orderId = this.orderId
            // this.form.goods_id = this.goodsId
            // getGoodsAttr(this.goodsId).then(res=>{
                
            // })
        } else {
            this.$refs['ruleForm'].resetFields()
        }
      }
    },
    mounted(){
        
    },
    methods: {
      handleClick(){
        getGoodsAttr(this.form.goods_id).then(res=>{
                this.colorList=res.color
                this.specList=res.spec
            })
      },
      cancle(){
        this.dialogVisible = false 
        this.form={
          orderId:'',
            color:'',
            spec:'',
            orderId:'',
            goods_id:''
        }
      },
        color(e){
            console.log(e);
            this.color=e
        },
        spec(e){
            this.spec=e
        },
      submit() {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.colorList.findIndex(e=>{
                if(e.value==this.form.color){
                    this.form.color=e.id
                }
            })
            this.specList.findIndex(e=>{
                if(e.value==this.form.spec){
                    this.form.spec=e.id
                }
            })
            console.log(this.form);
            setGoodsAttr({ ...this.form }).then(res => {
              this.dialogVisible = false
              this.$emit('getList', true)
            })
          } else {
            this.$message({
              message: '请检查表单错误',
              type: 'error'
            })
            return false
          }
        })
      },
      changeType(item){
        this.form.type=item
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  </style>
  